<template>
	<view class="page">
		<view class="flex benben-position-layout flex flex-wrap align-center numBalance_flex_0"
			:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx'}">
			<view class='flex flex-wrap align-center justify-between flex-sub numBalance_fd0_0'>
				<view class='flex flex-wrap align-center numBalance_fd0_0_c0' @tap.stop="handleJumpDiy" data-type="back"
					data-url="1">
					<text class='fu-iconfont2  numBalance_fd0_0_c0_c0'>&#xe794;</text>
				</view>
				<view class='flex flex-wrap align-center'>
					<text class='numBalance_fd0_0_c1_c0'>充值</text>
				</view>
				<view class='flex flex-wrap align-center numBalance_fd0_0_c1'>
					
				</view>
			</view>

		</view>
		<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>

		<view class="flex flex-direction flex-wrap align-stretch benben-flex-layout numBalance_flex_2" v-if="group == 0">
			<text class='numBalance_fd2_0'>充值金额</text>
			<benben-select-diy ref="showSelectPopup1661338112360"
				class-name='numBalance_fd2_1' :items.sync="rechargetype"
				v-model="recharge_id" :label.sync="recharge_money" default-type="id" default-label="money"
				:allow-cancel='false' type="radio" :disabled='false' @change="rulesChange">
				<template v-for='(item,key0) in rechargetype'>
					<view v-if="item.isSelected"
						class='flex flex-direction flex-wrap align-stretch flex numBalance_fd2_1_c0' :key="key0"
						@tap="$refs.showSelectPopup1661338112360.tapHandle(key0)">
						
						<text class='numBalance_fd2_1_c0_c1'>{{Number(item.money)}}元
						</text>
						<view class='flex flex-wrap align-center justify-center numBalance_fd2_1_c0_c2'>
							<text>{{Number(item.add_money)}}</text>
							<text>金币</text>
						</view>
					</view>
					<view v-else class='flex flex-direction flex-wrap align-stretch flex numBalance_fd2_1_c1'
						:key="key0" @tap="$refs.showSelectPopup1661338112360.tapHandle(key0)">
						<text class='numBalance_fd2_1_c1_c0'>{{Number(item.money)}}元
						</text>
						<view class='flex flex-wrap align-center justify-center numBalance_fd2_1_c1_c1'>
							<text>{{Number(item.add_money)}}</text>
							<text>金币</text>
						</view>
					</view>
				</template>
			</benben-select-diy>
		</view>
		
		<view class="flex flex-direction flex-wrap align-stretch benben-flex-layout numBalance_flex_2" v-if="group == 1">
			<text class='numBalance_fd2_0'>充值金额</text>
			<benben-select-diy ref="showSelectPopup1661338112360"
				class-name='flex flex-wrap align-center flex numBalance_fd2_1' :items.sync="rechargetype"
				v-model="recharge_id" :label.sync="recharge_money" default-type="id" default-label="money"
				:allow-cancel='false' type="radio" :disabled='false' @change="rulesChange">
				<template v-for='(item,key0) in rechargetype'>
					<view v-if="item.isSelected"
						class='align-stretch flex numBalance_fd2_1_c0' :key="key0"
						@tap="$refs.showSelectPopup1661338112360.tapHandle(key0)">
						<image class='numBalance_fd2_1_c0_c0' mode="aspectFit" :src='STATIC_URL+"54.png"'></image>
						<view class='flex flex-wrap align-center justify-center numBalance_fd2_1_c0_c2'>
							<text>{{item.name}}</text>
						</view>
					</view>
					<view v-else class='align-stretch flex numBalance_fd2_1_c1'
						:key="key0" @tap="$refs.showSelectPopup1661338112360.tapHandle(key0)">
						<view class='flex flex-wrap align-center justify-center numBalance_fd2_1_c1_c1'>
							<text>{{item.name}}</text>
						</view>
					</view>
				</template>
			</benben-select-diy>
		</view>

		<view class="flex flex-direction flex-wrap align-center benben-position-layout flex numBalance_flex_3">
			<button class='numBalance_fd3_0' @tap.stop="getRecharge">充值</button>

		</view>
		<view :style="{height: '190rpx'}"></view>

	</view>
</template>
<script>
	import applyPayMixin from './applyPay.js'
	export default {
		mixins: [applyPayMixin],
		components: {},

		data() {
			return {
				"rechargetype": [],
				"recharge_id": "1",
				"recharge_money": "",
				"balanceInfo": {},
				"group": 0,  // 0安卓  1ios
				"app_name": "",
				"add_money": "",
			};
		},
		computed: {

		},
		watch: {},
		onLoad(options) {
			// if(uni.getSystemInfoSync().platform == 'android') {
			// 	this.group = 0;
			// } else {
			// 	this.group = 1;
			// }
			this.getRechargeRules();
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {
			
		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			// 充值金额列表
			getRechargeRules() {
				this.$api.post(global.API_VERSION + '/647d82400ac77', {
					// group: uni.getSystemInfoSync().platform
					group: 'android'
				}).then(res => {
					// console.log(res);
					if (res.data.code == 1) {
						this.rechargetype = res.data.data;
						if (this.rechargetype.length > 0) {
							this.recharge_id = this.rechargetype[0].id;
							this.recharge_money = this.rechargetype[0].money;
							if (this.group == 1) {
								this.app_name = this.rechargetype[0].app_name;
								this.add_money = this.rechargetype[0].add_money;
								this.ids = this.rechargetype.map(t => t.app_name);
								uni.setStorageSync('ids', this.ids);
							}
						}
					} else {
						this.$message.info(res.data.msg);
					}
				})
			},
			// 充值跳转支付
			getRecharge() {
				uni.redirectTo({
					url: '/pages/qbgl/payImmediately/payImmediately?recharge_id=' + this.recharge_id
				})
			},
			rulesChange(e) {
				// console.log(e);
				this.recharge_money = e.value;
				this.recharge_id = e.label;
				this.rechargetype.forEach((v, k) => {
					if (this.recharge_id == v.id) {
						this.app_name = this.rechargetype[k].app_name;
						this.add_money = this.rechargetype[k].add_money;
					}
				})
				
			},
			
			// 苹果支付
			async applyPayHandle(sn) {
				this.$message.info('支付中，请稍等...');
				console.log(this.app_name);
				let _this = this;
				uni.requestPayment({
					provider: 'appleiap',
					// orderInfo: _this.app_name,
					orderInfo: {productid: _this.app_name},
					success: e => {
						console.log('支付成功', e, '-', e.transactionIdentifier);
						_this.applyPaySuccess(sn);
						
					},
					fail: err => {
						console.log(err);
						uni.showModal({ content: "取消支付", showCancel: false })
					},
					complete: e=> {
						console.log(e);
					}
				})
			},
			// 苹果支付回调  post638ebd5a49f80
			applyPaySuccess(sn) {
				this.$api.post(global.apiUrls.post638ebd5a49f80, {
					order_sn: sn
				}).then(res => {
					if (res.data.code == 1) {
						this.$message.info('支付成功');
						if (this.sex_type == 2) {
							setTimeout(() => {
								uni.navigateBack();
							}, 800)
						} else{
							this.pay_id = 3;
							setTimeout(() => {
								uni.redirectTo({
									url: '/pages/Mycenter/payOut/payOut?payType=' + this.pay_id
								})
							}, 800)
						}
					} else {
						this.$message.info(res.data.msg);
					}
				})
			},
		}
	};
</script>
<style lang="scss" scoped>
	.numBalance_fd3_0 {
		background: #6A0002;
		background-size: 100% !important;
		border-radius: 44rpx 44rpx 44rpx 44rpx;
		font-size: 32rpx;
		color: #fff;
		width: 686rpx;
		height: 80rpx;
		line-height: 80rpx;
		font-weight: 500;
	}

	.numBalance_fd3_1_c0 {
		font-size: 26rpx;
		font-weight: 400;
		color: rgba(153, 153, 153, 1);
	}

	.numBalance_fd3_1_c1 {
		font-size: 26rpx;
		font-weight: 500;
		// color: #333;
		color: #EB8571;
	}

	.numBalance_flex_3 {
		background: rgba(247, 247, 247, 1);
		background-size: 100% !important;
		width: 750rpx;
		height: 140rpx;
		overflow: hidden;
		z-index: 10;
		bottom: calc(0rpx + var(--window-bottom));
		background-size: 100% auto !important;
	}

	.numBalance_fd2_0 {
		margin: 0rpx 32rpx 24rpx 32rpx;
		font-weight: 500;
		font-size: 32rpx;
		color: #333;
	}

	::v-deep .numBalance_fd2_1 {
		padding: 0rpx 0rpx 0rpx 25rpx;
	}

	.numBalance_fd2_1_c0 {
		// border: 1px solid #6A0002;
		margin: 0rpx 7rpx 36rpx 7rpx;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		position: relative;
		// padding: 15rpx 44rpx 15rpx 44rpx;
		width: 31%;
		height: 138rpx;
		text-align: center;
		padding-top: 15rpx;
		background: rgba(139, 6, 13, 0.7);
		float: left;
		margin-right: 1%;
	}

	.numBalance_fd2_1_c0_c0 {
		width: 44rpx;
		height: 44rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		position: absolute;
		top: -3rpx;
		right: -3rpx;
	}

	.numBalance_fd2_1_c0_c1 {
		font-size: 28rpx;
		font-weight: 400;
		color: #fff;
		margin: 0rpx 0rpx 16rpx 0rpx;
	}

	.numBalance_fd2_1_c0_c2 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 500;
		color: #fff;
		margin: 0 auto;
	}

	.numBalance_fd2_1_c1 {
		// border: 2px solid #CBCBCB;
		margin: 0rpx 7rpx 36rpx 7rpx;
		// padding: 17rpx 44rpx 17rpx 44rpx;
		width: 31%;
		height: 138rpx;
		text-align: center;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		padding-top: 15rpx;
		background: #F5F5F5;
		float: left;
		margin-right: 1%;
	}

	.numBalance_fd2_1_c1_c0 {
		font-size: 28rpx;
		font-weight: 400;
		color: rgba(102, 102, 102, 1);
		margin: 0rpx 0rpx 16rpx 0rpx;
	}

	.numBalance_fd2_1_c1_c1 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 700;
		color: rgba(102, 102, 102, 1);
		margin: 0 auto;
	}

	.numBalance_flex_2 {
		background: #fff;
		background-size: 100% !important;
		background-size: 100% auto !important;
		padding: 40rpx 0rpx 0rpx 0rpx;
		margin: 0rpx 0rpx 10rpx 0rpx;
	}

	.numBalance_fd1_0 {
		margin: 0rpx 0rpx 28rpx 0rpx;
	}

	.numBalance_fd1_0_c0 {
		font-size: 32rpx;
		font-weight: 700;
		color: rgba(230, 51, 52, 1);
		line-height: 64rpx;
	}

	.numBalance_fd1_0_c1 {
		color: rgba(230, 51, 52, 1);
		font-weight: 700;
		font-size: 64rpx;
	}

	.numBalance_fd1_1 {
		font-size: 28rpx;
		font-weight: 400;
		color: rgba(102, 102, 102, 1);
	}

	.numBalance_flex_1 {
		background: #fff;
		background-size: 100% !important;
		background-size: 100% auto !important;
		padding: 64rpx 0rpx 44rpx 0rpx;
		margin: 0rpx 0rpx 20rpx 0rpx;
	}

	.numBalance_fd0_0 {
		margin: 0rpx 32rpx 0rpx 32rpx;
	}

	.numBalance_fd0_0_c0 {
		width: 162rpx;
	}

	.numBalance_fd0_0_c0_c0 {
		font-size: 32rpx;
		font-weight: 600;
		color: #333;
	}
	.numBalance_fd0_0_c1 {
		width: 162rpx;
	}

	.numBalance_fd0_0_c1_c0 {
		font-size: 36rpx;
		font-weight: 500;
		color: #333;
		line-height: 88rpx;
	}

	.numBalance_fd0_0_c2_c0 {
		font-size: 32rpx;
		font-weight: 400;
		color: #333;
	}

	.numBalance_flex_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		background-size: 100% !important;
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background-size: 100% auto !important;
	}

	.page {
		min-height: calc(100vh - var(--window-bottom));
		background: rgba(247, 247, 247, 1);
		background-size: 100% auto !important;
	}
</style>
